//
//  PeopleModel.m
//  ModelJsonDemo
//
//  Created by苏沫离 on 2018/3/21.
//  Copyright © 2018年 longlong. All rights reserved.
//

#import "PeopleModel.h"
#import <objc/runtime.h>

@implementation PeopleModel

+ (NSDictionary *)arrayContainModelClass
{
    return @{@"carsArray":@"CarModel",
             @"dogsArray":@"DogModel"
             };
}

//重写 输出方法 打印类信息
- (NSString *)description
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    unsigned int count = 0;
    Ivar *iavrList = class_copyIvarList(self.class, &count);
    for (int i = 0; i < count; i ++)
    {
        Ivar ivar = iavrList[i];
        NSString *key = [NSString stringWithUTF8String:ivar_getName(ivar)];
        if ([self valueForKey:key])
        {
            [mutableDict setValue:[self valueForKey:key] forKey:key];
        }
    }
    free(iavrList);
    return [NSDictionary dictionaryWithDictionary:mutableDict];
}


@end
